package com.zgc.demo.j2dbc.config;

import dev.miku.r2dbc.mysql.MySqlConnectionFactoryProvider;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;

import static io.r2dbc.spi.ConnectionFactoryOptions.*;
import static io.r2dbc.spi.ConnectionFactoryOptions.PORT;

public class MysqlConnectionConfig {
    public static ConnectionFactory getConnectionFactory() {
        final ConnectionFactory connectionFactory = new MySqlConnectionFactoryProvider().create(
                ConnectionFactoryOptions.builder()
                .option(DRIVER, "mysql") //
                .option(USER, "root") //
                .option(PASSWORD, "root") //
                .option(DATABASE, "testdb") //
                .option(HOST, "localhost") //
                .option(PORT, 3306) //
                .build()
        );
        return connectionFactory;
    }

    public static ConnectionFactory getTestConnectionFactory() {
        final ConnectionFactory connectionFactory = new MySqlConnectionFactoryProvider().create(
                ConnectionFactoryOptions.builder()
                        .option(DRIVER, "mysql") //
                        .option(USER, "root") //
                        .option(PASSWORD, "root") //
                        .option(DATABASE, "testdb") //
                        .option(HOST, "localhost") //
                        .option(PORT, 3306) //
                        .build()
        );
        return connectionFactory;
    }
}
